package com.usf.jprovider.object.type;



public abstract class JType<T>{
	
	protected T value;
	protected String formatedValue;
	protected String format;
	
	public JType(){
		format = "";
		formatedValue = "";
	}
	public JType(T value, String format) {
		this.value = value;
		this.format = format;
		this.formatedValue = format(format);
	}
	public JType(String value, String format) throws Exception{
		set(value, format);	
	}
	
	public T getValue() {
		return value;
	}
	public String getFormatedValue() {
		return formatedValue;
	}
	public String getFormat() {
		return format;
	}

	public void set(String value, String format) throws Exception{
		this.value = parse(value, format);
		this.format = format;
		this.formatedValue = format(format);		
	}
	public void set(String value) throws Exception{
		this.value = parse(value, format);
		this.formatedValue = format(format);		
	}
	
	@Override
	public final boolean equals(Object obj) {
		JType<?> object = (JType<?>)obj;
		return value.equals(object.getValue()) ||
				formatedValue.equals(object.getFormatedValue());
	}
	@Override
	public final String toString() {
		return value.toString();
	}
		
	protected abstract T parse(String value, String format) throws Exception;
	protected abstract String format(String format);
	
}
